﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Gallery.DAL.Repositories;

namespace Gallery
{
    public partial class Gallery1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            LoadData();
        }

        private void LoadData()
        {

            var list = PictureRepository.FindAll().ToList();

            foreach (var item in list)
            {
                String link = "~/Files/" + item.PictureId.ToString() + "_" + item.FileName;
                String title = String.Format("{0}{1}{2}",
                    item.PictureName,
                    !item.DateCreated.HasValue ? "" : " " + item.DateCreated.Value.ToString("MM") + "/" + item.DateCreated.Value.ToString("yyyy"),
                    item.AuthorAge > 0 ? " (" + item.AuthorAge.ToString() + " years)" : "");

                HyperLink h = new HyperLink();
                h.CssClass = "fancybox-thumbs";
                h.Attributes.Add("title", title);
                //h.Attributes.Add("data-fancybox-group", "thumb");
                h.Attributes.Add("rel", "fancybox-thumb");
                h.NavigateUrl = link;

                Image img = new Image();
                img.CssClass = "imgSmall";
                img.ImageUrl = link;
                img.AlternateText = item.PictureName;

                h.Controls.Add(img);
                pnlContainer.Controls.Add(h);
            }
        }
    }
}